<?php
namespace framework{

    use Framework\Inspector as Inspector;
    use Framework\ArrayMethods as ArrayMethods;

	class Base {
        private $_inspector;
        
        public function __construct($options = array()){
            $this->_inspector = new Inspector($this);
            
            if(is_array($options) || is_object($options)){
                foreach($options as $key => $value){
                    $key = ucfirst($key);
                    $methods = "set{$key}";
                    $this->$method($value);
                }
            }
        }
        
        public function __call($name,$arguments){
            if(empty($this->_inspector)){
                throw new Exception("Call parent::__construct!");
            }
            
            $getMatches = StringMethods::match($name,"^get([a-zA-Z0-9]+)$");
            if(count($getMatches)){
                $normalized = lcfirst($getMatches[0]);
                $property = "_{$normalized}";
                
                if(property_exists($this,$property)){
                    $meta = $this->_inspector->getPropertyNeta($property);
                }
                
                if(empty($meta["@readwrite"]) && empty($meta['@read']) ){
                    throw $this->_getExcptionForWriteonly($normalized);
                }
                
                if(isset($this->$property)){
                    return $this->$property;
                }
                
                return null;
            }
        }
        
        $setMatches = StringMethods::match($name,"^set([a-zA-Z0-9]+)$");
        if(count($setMatches)){
            $normalized = lcfirst($setMatches[0]);
            $property = "_{$normalized}";
            
            if(property_exists($this, $property)){
                $meta = $this->_inspector->getPropertyMeta($property);
                
                if(empty($meta['@readwrite']) && empty($meta['@write']) ){
                    throw $this->getExceptionForReadonly($normalized);
                }
                
                $this->$property = $arguments[0];
                return $this;
            }
        }
	   throw $this->_getExceptionForImplememtation($name);
	}
	
}


















































